import { fabric } from 'fabric';

export const ShortLine = fabric.util.createClass(fabric.Rect, {
  type: 'shortLine',

  initialize: function (options) {
    options || (options = {});
    options.strokeWidth = 2;

    this.callSuper('initialize', options);
    this.set('stroke', options.stroke || null);
  },

  toObject: function () {
    return fabric.util.object.extend(this.callSuper('toObject'), {});
  },

  _render: function (ctx) {
    const h = this.height;
    const y = -this.height / 2;

    ctx.beginPath();
    ctx.moveTo(0, y);
    ctx.lineTo(0, y + h);
    ctx.closePath();

    this._renderPaintInOrder(ctx);
  }

  // todo: svg导出
});

declare module 'fabric' {
  namespace fabric {
    class ShortLine {
      static fromObject(object: fabric.Object, callback: Function): ShortLine;
    }
  }
}
